/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * Generic Collection Base Enumerator Class
 *     The abstract base class for supporting enumerations over collection  
 * class implementations.
 *--------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------
 * System Imports
 *-------------------------------------------------------------------------*/
#include "StdAfx.h"
#include "GenericCollectionBaseEnumerator.h"

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Generic;

namespace Adaptive
{
	namespace Foundation
	{
        /*--------------------------------------------------------------------------------
         * Constructor / Dispose / Destructor Methods
         *------------------------------------------------------------------------------*/
#pragma region Constructor / Dispose / Destructor Methods
        // Initializes a new instance of the class.
		generic<typename T>
		GenericCollectionBaseEnumerator<T>::GenericCollectionBaseEnumerator(System::Collections::Generic::ICollection<T>^ parentCollection)
        {
            _parentCollection = parentCollection;
			_index = -1;
        }
        // Deallocates internally allocated objects.
		generic<typename T>
        GenericCollectionBaseEnumerator<T>::~GenericCollectionBaseEnumerator()
        {
            _parentCollection = nullptr;
			_index = -1;
        }
        // Class destructor.
		generic<typename T>
        GenericCollectionBaseEnumerator<T>::!GenericCollectionBaseEnumerator()
        {
            _parentCollection = nullptr;
			_index = -1;
        }
#pragma endregion

        /*---------------------------------------------------------------------------
		 * Public Properties
		 *-------------------------------------------------------------------------*/
#pragma region Public Properties
        // Gets the current element in the collection.
		generic<typename T>
		T GenericCollectionBaseEnumerator<T>::Current::get()
        {
			T returnValue = T();

			returnValue =(T) ((GenericCollectionBase<T>^)_parentCollection)[_index];
            return returnValue;
		}
		generic<typename T>
		Object^ GenericCollectionBaseEnumerator<T>::CurrentObject::get()
        {
			Object^  returnValue = nullptr;

			returnValue =(Object^) ((GenericCollectionBase<T>^)_parentCollection)[_index];
            return returnValue;
		}
#pragma endregion

        /*---------------------------------------------------------------------------
		 * Public Methods/Functions
		 *-------------------------------------------------------------------------*/
#pragma region Public Methods/Functions
        // Advances the enumerator to the next element of the collection.
		generic<typename T>
        bool GenericCollectionBaseEnumerator<T>::MoveNext()
        {
            _index++;
            if (_index < _parentCollection->Count)
                return true;
            else
                return false;
        }
        // Sets the enumerator to its initial position, which is before the first element in the 
        // collection.
		generic<typename T>
        void GenericCollectionBaseEnumerator<T>::Reset()
        {
            _index = -1;
        }
#pragma endregion
	}
}